package com.village.friend.controller;

import com.village.friend.constant.MsgCodeEnum;
import com.village.friend.dto.request.UserComplaintAddDto;
import com.village.friend.dto.response.BaseResponse;
import com.village.friend.entity.User;
import com.village.friend.entity.UserComplaint;
import com.village.friend.redis.RedisService;
import com.village.friend.service.UserComplaintService;
import com.village.friend.utils.ParamUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/complaint")
@Api(tags = "用户举报模块")
public class UserComplaintController {
    @Autowired
    RedisService redisService;
    @Autowired
    public UserComplaintService userComplaintService;
    @ApiOperation("举报")
    @PostMapping("/add")
    public BaseResponse<String> add(@RequestBody UserComplaintAddDto param) {
        User userRedis = redisService.getUser(param.getToken());
        UserComplaint entry = new UserComplaint();
        entry.setUserId(userRedis.getUid());
        entry.setComplaintId(param.getComplaintId());
        entry.setType(param.getType());
        entry.setDetail(param.getDetail());
        entry.setImages(ParamUtils.listToJSONStr(param.getImages()));
        userComplaintService.save(entry);
        return new BaseResponse(MsgCodeEnum.SUCCESS, null);
    }
}
